package com.demo.dom4j;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;

import java.io.File;
import java.util.List;

public class Dom4jPaser {

    public static void parser(String path) {
        SAXReader saxReader = new SAXReader();
        File file = new File(path);

        try {
            Document document = saxReader.read(file);
            Element rootElement = document.getRootElement();
            System.out.println(rootElement.getName());
            List<Element> elements = rootElement.elements();

            for (Element element : elements)
            {
                System.out.println(element.getName());
                String statment = element.getTextTrim();
                System.out.println(statment);
            }
        } catch (DocumentException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        parser("/Users/jasper/Desktop/rds.xml");
    }
}
